package com.huangliusong.aspectJ.demo1;


import org.aopalliance.intercept.Joinpoint;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.context.annotation.Bean;

/**
 * 切面
 */
@Aspect
public class MyAspectAnno {

    @Before(value = " myPointCut1()")
    public void before(JoinPoint joinPoint){
        System.out.println("Before...."+joinPoint);
    }


    @AfterReturning(value = " myPointCut1()",returning="result")
    public  void afterReturing(Object result){
        //在后置通知中获取返回的内容
        System.out.println("后置通知...."+result);
    }

    @Around(value = "myPointCut3()")
    public Object around(ProceedingJoinPoint joinPoint)throws Throwable{
        System.out.println("环绕前=================");
        Object o=joinPoint.proceed();

        System.out.println("环绕后=================");
        return o;
    }

    @AfterThrowing(value = "execution(* com.huangliusong.aspectJ.demo1.ProductDao.findOne(..))",throwing = "e")
    public void afterthrow(Throwable e){
        System.out.println("异常================="+e.getMessage());
    }

    @After(value = "execution(*  com.huangliusong.aspectJ.demo1.ProductDao.findAll(..))")
    public void aafter(){
        System.out.println("最终通知");
    }

    @Pointcut(value = "execution(*  com.huangliusong.aspectJ.demo1.ProductDao.update(..))")
    private void myPointCut1(){}

    @Pointcut(value = "execution(*  com.huangliusong.aspectJ.demo1.ProductDao.update(..))")
    private void myPointCut2(){}

    @Pointcut(value = "execution(*  com.huangliusong.aspectJ.demo1.ProductDao.delete(..))")
    private void myPointCut3(){}
}
